package com.ruicar.afs.cloud.common.voucher.handle;

import com.ql.util.express.DefaultContext;
import com.ruicar.afs.cloud.common.voucher.Voucher;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.Map;

@Slf4j
public abstract class AbstractRunner implements VoucherRunner{
    /**
     * Gen voucher context default context
     * <p>Description: </p>
     *
     * @param voucher
     * @param paramMap param map
     * @return the default context
     */
    protected DefaultContext genVoucherContext(Voucher voucher, Map<String,Object> paramMap){
        log.debug("准备编号为【{}】凭证参数",voucher.getRuleNo());
        DefaultContext rtnContext = new DefaultContext();
        voucher.getVoucherAtomMappings().forEach(mapping->{
           rtnContext.put(mapping.getMappingName(), paramMap.get(mapping.getAtomKey())!=null?new BigDecimal(String.valueOf(paramMap.get(mapping.getAtomKey()))):BigDecimal.ZERO);
        });
        return rtnContext;
    }
}
